home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / DOpus-1541 / REXX / DOPUS / 1541 / 1541ReName.rexx < prev   
OS/2 REXX Batch file  |  1995-02-24  |  4KB  |  177 lines

  1. /*
  2.  *
  3.  * Rename file(s) on 1541 and Amiga from DOpus.
  4.  *
  5.  * (c) 1995 by Christer Bjarnemo  mr.bjarnemo@mn.medstroms.se
  6.  *
  7.  * Based on Twin-Dopus by Patrick Van Beem (patrick.van.beem@aobh.xs4all.nl),
  8.  * which based he's script on the DOpusLhaARexx package by Geoff Seeley.
  9.  *
  10.  */
  11.  
  12. dircmd = "Work:Emulators/A64/Utils/"    /* Note. If the file ENVARC:1541.PREFS */
  13. rxdir =  "Rexx:Dopus/1541/"             /* exists, that one will override the  */
  14. tmpdir = "t:"                           /* settings here...                    */
  15. DOpusPort   = 'DOPUS.1'
  16.  
  17. snuff = '22'x
  18.  
  19. if open(1,'env:1541.prefs','Read') then do
  20.         dircmd = readln(1)
  21.     rxdir  = readln(1)
  22.         tmpdir = readln(1)
  23.         end
  24. close(1)
  25.  
  26. dircmd = slashpath(dircmd)
  27. rxdir =  slashpath(rxdir)
  28. tmpdir = slashpath(tmpdir)
  29.  
  30. if ~show(l,"rexxsupport.library") then        
  31.     call addlib("rexxsupport.library",0,-30,0)
  32. if showlist('Ports', DOpusPort) = 0 then do
  33.    say 'Directory Opus Arexx port not found. Aborting.'
  34.    call CleanUp
  35. end
  36.  
  37. address(DOpusPort)
  38. options results
  39.  
  40. /* setup DOpus window and tell user what's happening */
  41. Busy on
  42. TopText "Renaming selected files..."
  43.  
  44. /* Get the destination path */
  45. 'Status 6 -1'
  46. GetEntry Result
  47. ToPath = Result
  48. if left(ToPath,1) = '*' then do
  49.    ToPath = SubStr(ToPath,2)
  50.    DoReread='TRUE'
  51. end
  52. else do
  53.    'Status 13 -1'
  54.    ToPath = result
  55.    if ToPath = '' then do
  56.       TopText "No destination directory selected."
  57.       call CleanUp
  58.    end
  59.    DoReread='FALSE'
  60. end
  61. ToPath=Quote(ToPath)
  62.  
  63. /* Get the current path and do file-copy, depending on the  */
  64. /* type of path (1541/normal path)                          */
  65. 'Status 6 -1'
  66. GetEntry Result
  67. FilePath = Result
  68.  
  69. /* 1541-way */
  70. if left(FilePath,1) = '*' then do
  71.    FilePath = SubStr(FilePath,2)
  72.    GetSelectedAll
  73.    SelectedEntries = result
  74.    if SelectedEntries = 'RESULT' then do
  75.       TopText "No files selected."
  76.       call CleanUp
  77.    end
  78.    NumberOfEntries = words(SelectedEntries)
  79.    do EntryNumber = 1 to NumberOfEntries
  80.       Index = word(SelectedEntries, EntryNumber)
  81.       GetEntry Index+1
  82.       Entry = result
  83.       File = strip(left(Entry,25))
  84.       if right(FilePath,1) = ':' then
  85.          File = FilePath || File
  86.       else
  87.          File = FilePath || '' || File
  88.  
  89. Getstring '"Rename this file?" "'file'"'
  90. newname = result
  91. if newname ~= file then do
  92.     address command dircmd'64Cmd >'tmpdir'1541.tmp "r:'newname'='File'" 8'
  93.     if open(1,tmpdir'1541.tmp','Read') then do
  94.             Do for 8 ; tmp = readln(1) ; End
  95.         say tmp
  96.         Toptext tmp
  97.             close(1)
  98.             end
  99.     end
  100.  
  101.       selection = Index||' 0 0'
  102.       SelectEntry selection
  103.    end
  104. end
  105.  
  106. /* Normal way */
  107. else do
  108.     rename
  109. end
  110.  
  111.  
  112. 'DisplayDir -1'
  113.  
  114. if DoReread='TRUE' then do
  115.    address arexx rxdir'1541Dir.rexx'
  116. end
  117.  
  118. call CleanUp
  119.  
  120. exit
  121.  
  122. /*---------------------------------------------------------------------------*/
  123.  
  124. CleanUp: /* Remove any files and exit */
  125.    Busy off
  126.    exit
  127. return
  128.  
  129. /*--------------------------------------------------------------------------*/
  130.  
  131. Quote: procedure /* add quotes to string */
  132.    parse arg string
  133. return '"'||string||'"'
  134.  
  135. /*--------------------------------------------------------------------------*/
  136.  
  137. GetWord: procedure /* get word from '|' separated string */
  138.  
  139.   parse arg number,words
  140.  
  141.   if(left(words,1) ~= '|') then
  142.      words = '|'||words
  143.   do i=1 to number
  144.      idx = index(words, '|');
  145.      words = substr(words, idx+1)
  146.   end
  147.   end = index(words, '|') - 1
  148.   if words = "" then
  149.      return ""
  150.  
  151.   ret_str = substr(words, 1, end)
  152. return ret_str
  153.  
  154. /*--------------------------------------------------------------------------*/
  155.  
  156. CountWords: procedure /* count words from '|' separated string */
  157.  
  158.    parse arg words
  159.  
  160.    count = 0
  161.    idx = index(words, '|')
  162.    do while idx ~= 0
  163.      count = count + 1
  164.      words = substr(words, idx+1)
  165.      idx = index(words, '|')
  166.    end
  167. return count
  168.  
  169. /*---------------------------------------------------------------------------*/
  170. Slashpath: procedure /* Put a (/) or (:) at the end of filenames (if neccessary) */
  171. parse arg string
  172.     if right(string,1) ~= ':' & right(string,1) ~= '/'  then do
  173.         string = string'/'
  174.         end
  175. return string
  176.  
  177.